package tagcloud.gui;

import java.awt.GridBagLayout;
import javax.swing.JPanel;
import java.awt.GridBagConstraints;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.BorderFactory;
import javax.swing.SwingConstants;
import javax.swing.JButton;
import javax.swing.ImageIcon;
import java.awt.Insets;
import java.awt.event.ActionListener;

public class LoginPanel extends JPanel {

	private static final long serialVersionUID = 1L;
	private JLabel usernameLabel = null;
	private JLabel passwordLabel = null;
	private JTextField usernameTextField = null;
	private JPasswordField passwordTextField = null;
	private JLabel descriptionLabel = null;
	private JButton loginButton = null;
	private ActionListener parentActionListener;
	
	/**
	 * This is the default constructor
	 */
	public LoginPanel(ActionListener parentActionListener) {
		super();
		this.parentActionListener = parentActionListener;
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		GridBagConstraints gridBagConstraints5 = new GridBagConstraints();
		gridBagConstraints5.gridx = 2;
		gridBagConstraints5.weightx = 0.0D;
		gridBagConstraints5.anchor = GridBagConstraints.EAST;
		gridBagConstraints5.insets = new Insets(4, 0, 0, 0);
		gridBagConstraints5.gridy = 3;
		GridBagConstraints gridBagConstraints = new GridBagConstraints();
		gridBagConstraints.gridx = 0;
		gridBagConstraints.gridwidth = 3;
		gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
		gridBagConstraints.insets = new Insets(0, 0, 4, 0);
		gridBagConstraints.gridy = 0;
		descriptionLabel = new JLabel();
		descriptionLabel.setText("");
		descriptionLabel.setIcon(new ImageIcon(getClass().getResource("/images/logo.png")));
		descriptionLabel.setHorizontalAlignment(SwingConstants.CENTER);
		GridBagConstraints gridBagConstraints4 = new GridBagConstraints();
		gridBagConstraints4.fill = GridBagConstraints.BOTH;
		gridBagConstraints4.gridy = 2;
		gridBagConstraints4.weightx = 1.0;
		gridBagConstraints4.gridwidth = 2;
		gridBagConstraints4.gridx = 1;
		GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
		gridBagConstraints3.fill = GridBagConstraints.BOTH;
		gridBagConstraints3.gridy = 1;
		gridBagConstraints3.weightx = 1.0;
		gridBagConstraints3.gridwidth = 2;
		gridBagConstraints3.gridx = 1;
		GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
		gridBagConstraints2.gridx = 0;
		gridBagConstraints2.fill = GridBagConstraints.HORIZONTAL;
		gridBagConstraints2.ipadx = 10;
		gridBagConstraints2.gridy = 2;
		passwordLabel = new JLabel();
		passwordLabel.setText("Password:");
		GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
		gridBagConstraints1.gridx = 0;
		gridBagConstraints1.fill = GridBagConstraints.HORIZONTAL;
		gridBagConstraints1.ipadx = 10;
		gridBagConstraints1.gridy = 1;
		usernameLabel = new JLabel();
		usernameLabel.setText("Username:");
		this.setSize(640, 480);
		this.setLayout(new GridBagLayout());
		this.setBorder(BorderFactory.createEmptyBorder(0, 192, 0, 192));
		this.setName("Login Panel");
		this.add(usernameLabel, gridBagConstraints1);
		this.add(passwordLabel, gridBagConstraints2);
		this.add(getUsernameTextField(), gridBagConstraints3);
		this.add(getPasswordTextField(), gridBagConstraints4);
		this.add(descriptionLabel, gridBagConstraints);
		this.add(getLoginButton(), gridBagConstraints5);
	}

	/**
	 * This method initializes usernameTextField	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getUsernameTextField() {
		if (usernameTextField == null) {
			usernameTextField = new JTextField();
		}
		return usernameTextField;
	}

	/**
	 * This method initializes passwordTextField	
	 * 	
	 * @return javax.swing.JPasswordField	
	 */
	private JPasswordField getPasswordTextField() {
		if (passwordTextField == null) {
			passwordTextField = new JPasswordField();
		}
		return passwordTextField;
	}

	/**
	 * This method initializes loginButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	protected JButton getLoginButton() {
		if (loginButton == null) {
			loginButton = new JButton();
			loginButton.setText("Login");
			loginButton.addActionListener(parentActionListener);
		}
		return loginButton;
	}

}
